package com.thinkfit.jy.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.thinkfit.jy.R;

/**
 * 用户信息修改确认弹窗
 */
public class UserPopupWindow extends PopupWindow implements View.OnClickListener , PopupWindow.OnDismissListener {

    private Context mContext;

    private View view;

    public UserPopupWindow(Context context, OnUserOlick userOlick){
        mContext = context;
        this.userOlick = userOlick;
//        view = LayoutInflater.from(context).inflate(R.layout.activity_dialog, null);
        view = LayoutInflater.from(context).inflate(R.layout.item_dialog, null);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvMsg = view.findViewById(R.id.tv_info);
        TextView btn1 = view.findViewById(R.id.tv_left);
        TextView btn2 = view.findViewById(R.id.tv_right);
        tvTitle.setVisibility(View.INVISIBLE);
        tvMsg.setText(R.string.app_to_modify_user_information);
        btn1.setText(R.string.app_cancel);
        btn2.setText(R.string.app_ok);

        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

        this.setContentView(view);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();

        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(false);
        // 实例化一个ColorDrawable颜色为半透明
//        ColorDrawable dw = new ColorDrawable(Color.parseColor("#4D000000"));
//        ColorDrawable dw = new ColorDrawable(Color.parseColor("#ffffff"));
        // 设置SelectPicPopupWindow弹出窗体的背景
//        this.setBackgroundDrawable(dw);
        this.setOnDismissListener(this);

    }

    public void show(Activity context) {
        showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_left:
                dismiss();
                break;
            case R.id.tv_right:
                userOlick.onClick();
                dismiss();
                break;
        }
    }

    @Override
    public void onDismiss() {
          dismiss();
    }

    OnUserOlick userOlick;

    public interface OnUserOlick{
        void onClick();
    }
}
